package com.ivi.car.module.store.view.adapter;

import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ivi.car.R;
import com.ivi.car.module.store.model.StoreBean;
import com.wm.machine.baselibrary.utils.imageutils.glide.ImageLoader;

import java.util.List;

/**
 * Created by wjj on 2018/3/9.
 */

public class StoreAdapter extends BaseQuickAdapter<StoreBean, BaseViewHolder> {
    public StoreAdapter(int layoutResId, List data) {
        super(layoutResId, data);
    }

    private boolean isClick = true;
    @Override
    protected void convert(BaseViewHolder helper, StoreBean item) {
        int position = helper.getLayoutPosition();
        if (isClick && position == 0) {
            item.setSelect(true);
            isClick = false;
        }
        ImageView storeIcon = helper.getView(R.id.store_icon);
        Glide.with(mContext)
                .load(item.getStoreUrl())
                .into(storeIcon);
        /*ImageLoader.with(mContext).url("https://travel.12306.cn/imgs/resources/uploadfiles/images/a9b9c76d-36ba-4e4a-8e02-9e6a1a991da0_news_W540_H300.jpg")
        .into(storeIcon);*/
        helper.setText(R.id.store_name, item.getStoreName())
                .setText(R.id.store_address, item.getStoreAddress())
                .setText(R.id.store_distance, item.getStoreDistance());
        TextView storeYiZhan = helper.getView(R.id.store_yi);
        TextView storeRecommend = helper.getView(R.id.store_recommend);
        ImageView checkIcon = helper.getView(R.id.store_check);
        TextView storeName = helper.getView(R.id.store_name);
        TextView storeAddress = helper.getView(R.id.store_address);
        storeName.setTextColor(item.getSelect() ? Color.parseColor("#32CD99") : Color.WHITE);
        storeAddress.setTextColor(item.getSelect() ? Color.parseColor("#32CD99") : Color.GRAY);
        checkIcon.setImageResource(item.getSelect() ? R.mipmap.checked_icon : R.mipmap.unchecked_icon);
        storeYiZhan.setVisibility(item.isYiZhan() ? View.VISIBLE : View.GONE);
        storeRecommend.setVisibility(item.isRecommend() ? View.VISIBLE : View.GONE);
    }
}

